<!--
 * @Descripttion: 
 * @version: 
 * @Author: lyw
 * @Date: 2022-06-29 16:05:53
 * @LastEditors: fengweicong 75202172+fengweicong@users.noreply.github.com
 * @LastEditTime: 2022-07-13 20:08:32
-->
<template>
  <div class="register">
    <h2>注册</h2>
    <el-form>
      <el-form-item>
        <el-row>
          <el-col :span="4">手机号</el-col>
          <el-col :span="20">
            <el-input v-model="register.phone" placeholder="请输入手机号">
            </el-input>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item>
        <el-row>
          <el-col :span="4">密码</el-col>
          <el-col :span="20">
            <el-input v-model="register.password" placeholder="请输入密码">
            </el-input>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item>
        <el-row>
          <el-col :span="4">确认密码</el-col>
          <el-col :span="20">
            <el-input v-model="register.password2" placeholder="请再次输入密码">
            </el-input>
          </el-col>
        </el-row>
      </el-form-item>
    </el-form>
    <el-button type="primary" class="loginButton" @click="certainRegister"
      >注册</el-button
    >
  </div>
</template>

<script>
export default {
  name: "Register",
  data() {
    return {
      register: {
        phone: "",
        password: "",
        password2: "",
      },
    };
  },
  methods: {
    async certainRegister() {
      //用户注册
      if (this.register.password != this.register.password2) {
        this.$message.error("两次密码不一致");
        return;
      }
      this.$API.addLoginAccount({
        account: this.register.phone,
        account_password: this.register.password,
      }).then((res) => {
        if (res.status == 201) {
          return this.$API.addPurchaser({
            "account_id": res.data.id,
            "self_profile": null,
            "name": null,
            "id_card_number": null,
            "phone": null,
            "area": null,
          })
        }
      }).then(res => {
        if (res.status == 201) {
          this.$message.success("注册成功");
          this.$router.push("/login/login");
        }
      })
    },
  },
};
</script>
<style>
.register {
  width: 350px;
  height: 300px;
  background: #eee8e8;
  padding: 20px;
  text-align: center;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
</style>